<? 
session_start();
if(!session_is_registered(uid)){
    echo "You have to login to view this page!</br></br>";
    echo "Click here to return to the "; 
    echo '<a href="./../index.php" title="Login">Login Page</a></br></br>';
    echo "Or sign up using this link ";
    echo '<a href="./../Registration/registration.html" title="Registration">Registration Page</a>';
exit();
}
?>

<html>

    <table border='1'>
        <tr>
          <th>Category</th>
          <th>Name</th>
          <th>Type</th>         
          <th>Supplier</th>
          <th>Date Purchased</th>
          <th>Cost</th>
        </tr>
<?php

    //Manual SQL Connection
    $con = mysql_connect("localhost", "root", "root") or die ( "Error connectiong to DB: ".mysql_error());
       
    mysql_select_db("reeferslog", $con) or die ( "Error selecting specific DB, reefeerslog: ".mysql_error());
    
    //SQL query
    $result = mysql_query("SELECT * FROM livestock where user_id='". $_SESSION['uid'] ."'");

    //Fetches the table results to display for user
    while ($row = mysql_fetch_array($result)): ?>
      
      <td><?php echo $row['category']; ?></td>
      <td><?php echo $row['name']; ?></td>
      <td><?php echo $row['type']; ?></td>
      <td><?php echo $row['supplier']; ?></td>
      <td><?php echo $row['purchase_date']; ?> </td>
      <td><?php echo $row['cost']; ?></td>
      
      <!--Offers the Edit and Delete functions for user entered data-->
      <td><?php echo '<a href="editstock.php?action=edit&lv_id=' . $row['lv_id'] .' ">[EDIT]</a>';?></td>
      <td><?php echo '<a href="deletestock.php?type=live&lv_id=' . $row['lv_id'] .' ">[DELETE]</a>';?></td> 
    </td>
    </tr>
    <?php
    endwhile;
    mysql_close($con);
    ?>
  </table>
    </br>
    <a href="http:./../WelcomePage/WelcomePage.php">Home Page</a>
</html>